define(['jquery','api','util','user','Vue','text!pages/user/newaddress.html'],function($,api,util,user,Vue,tpl){
    var vm,
        timer,
        goodscode,
        controller={
        init:function(code){
        	goodscode=code;
        	api.footerShow(0);
		   	api.setTitle('新建收货地址');//商品展示期
		   	api.headerShow(1);
			api.headerTitle('新建收货地址');
		   	
            if(vm){
		   	   vm.show=true;
		   }else{
		   	   this.render();
		   } 

        },
        render:function(){
        	var that = this;
        	$('#pages').append('<div id="newaddress"></div>');
           	vm = new Vue({
            	el: '#newaddress',
              	data: {
                  	show:true,
                  	desc:'',
                  	goods:{}
              	},
              	template:tpl
           	});
        },
        loadGoods:function(code){
        	api.goodsInfo({
        		data:{goodscode:code},
        	    success:function(rs){
	    	      	if(rs.retcode==='0'){
	        	      	var items=[];
		    	      	if(rs.data && rs.data.length){
		    	      		goodsModel.addGoods(rs.data);
		    	      		var goods = goodsModel.codeToGoods[code];
			        		vm.goods = goods ? goods : {};
		    	      	}
	    	      	}else if(rs.retcode !== '0'){
	                    util.dealErrorCode(rs.retcode);
	               }
	        	}
        	});
        	
	    },
	    loadDesc: function(goodscode) {
	    	vm.descLoading = true;

        	api.goodsDesc(
        		goodscode,
        		function(rs){//suc
            		if (rs.retcode == 0) {
            			vm.descLoading = false;
                        vm.desc = rs.data.goodsdesc; //商品介绍
                        vm.subscription = rs.data.goodssubscription;//认购说明
                    }
            	},
            	function(){//err
            		vm.descLoading = false;
            	}
        	);
        },
	    onRouteChange:function(){
	    	if(vm)vm.show=false;
	    }
    }
    return controller;
});